package org.takeback.chat.service.admin;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.takeback.core.service.MyListServiceInt;

@Service("exchangeAdminService")
public class ExchangeAdminService extends MyListServiceInt {
	@Transactional
	public void save(Map<String, Object> req) {
		Map<String, Object> data = (Map) req.get("data");
		String status = (String) data.get("status");
		if ("2".equals(status)) {
			Integer id = Integer.valueOf(data.get("id").toString());

			String hql = "select count(*) from PubExchangeLog where id=:id and status='2'";
			Long l = Long.valueOf(this.dao.count(hql, ImmutableMap.of("id", id)));
			if (l.longValue() == 0L) {
				Integer uid = Integer.valueOf(data.get("uid").toString());
				Double money = Double.valueOf(data.get("money").toString());
				String upd = "update PubUser set money =coalesce(money,0) + :money where id=:uid";
				this.dao.executeUpdate(upd,
						ImmutableMap.of("money", Double.valueOf(data.get("money").toString()), "uid", uid));
			}
		}
		super.save(req);
	}
}
